package com.samsung.zhangsai;

import org.junit.Test;

public class Project1_Babygin {

	private int[] data;

	@Test
	public void test() {
		initdata();
		printData(data);
		sortdata(data);
		one_triptele(data);
		one_run(data);
		sortdata(data);
		printData(data);
		lastdata(data);
	}

	public void initdata() {
		data = new int[] { 1, 2, 3, 3, 4, 5 };
	}

	/**
	 * 初始化数组并进行从大到小排序
	 */
	public void printData(int[] data) {
		System.out.print("6张扑克牌上的数值为：");
		for (int i : data) {
			System.out.print(" " + i);
		}
		System.out.println("");
	}

	/**
	 * 冒泡排序
	 * 
	 * @param data
	 *            数组
	 */
	public void sortdata(int[] data) {
		for (int i = 0; i < data.length; i++) {
			for (int j = 0; j < data.length - i - 1; j++) {
				if (data[j] > data[j + 1]) {
					int temp = data[j];
					data[j] = data[j + 1];
					data[j + 1] = temp;
				}
			}
		}
	}

	public void one_run(int[] data) {
		int m = 0;
		int n = 0;
		int z = 0;
		for (int i = 1; i < data.length; i++) {
			if (data[i] == data[0] + 1) {
				n = i;
			}
			if (data[i] == data[0] + 2) {
				z = i;
				data[m] = -300;
				data[n] = -200;
				data[z] = -100;
			}
		}

	}

	/**
	 * 如果数组中有至少一个triptele，先将数组中的第一个triptele都置为-10
	 * 
	 * @param data
	 *            初始化的数组
	 */
	public void one_triptele(int[] data) {
		// 统计相等数值的个数
		int count = 0;
		for (int i = 1; i < data.length; i++) {
			if (i == 1) {
				if (data[i - 1] == data[i] && data[i] == data[i + 1]) {
					count++;
					if (count == 1) {
						data[i - 1] = data[i] = data[i + 1] = -50;
						break;
					}
				}
			}
			if (i > 1) {
				if (data[i - 1] == data[i] && data[i] == data[i - 2]) {
					count++;
					if (count == 1) {
						data[i - 2] = data[i - 1] = data[i] = -50;
						break;
					}
				}
			}
		}
	}

	public void lastdata(int[] data) {
		if (data[3] == data[4] && data[4] == data[5]) {
			System.out.println("该数组为Baby-Gin!");
		} else if (data[3] + 1 == data[4] && data[4] + 1 == data[5]) {
			System.out.println("该数组为Baby-Gin!");
		} else {
			System.out.println("该数组不是Baby-Gin!");
		}
	}

}
